<template>
  <app-container>
    <app-block>
      <div v-for="(item,index) in dataArr" :key="index">
        <zm-table-data :data="item.arr" :columns="columns(item.label)" :show-page="false" :border="false" :stripe="false" class="mb20">
          <!-- <zm-table-column prop="approveName" :label="item.label" fixed="left" min-width="120">
            <template slot-scope="scope">
              <el-image style="width: 60px; height: 60px;border-radius:10px;" :src="scope.row.iconUrl" fit="contain" />
              <div>{{scope.row.approveName}}</div>
            </template>
          </zm-table-column> -->
        </zm-table-data>
      </div>
    </app-block>
    <new-panel v-if="updateVisible" v-model="updateVisible" :row-info="rowInfo" @after-save="afterSave"></new-panel>
  </app-container>
</template>

<script>
import tableMixin from '@/mixins/zmTableMixin'
import NewPanel from './New'
import { columns } from './const'
import approveProcessApis from '@/api/src/approveProcess'
export default {
  components: { NewPanel },
  mixins: [tableMixin],
  data () {
    return {
      // columns: columns(this),
      dataArr: [],
      updateVisible: false,
      rowInfo: {}
    }
  },
  computed: {
  },
  watch: {},
  created () {
    this.loadList()
  },
  methods: {
    columns (label) {
      return columns(this, label)
    },
    async loadList () {
      let type = ['3', '4', '5', '6', '9', '10', '11', '12', '13']
      const res = await approveProcessApis.getList()
      const arrProdulist = res.filter(i => i.processType === '1' || i.processType === '2' || i.processType === '8')
      const arrBusiness = res.filter(i => type.includes(i.processType))
      const arrFinance = res.filter(i => i.processType === '7')
      this.dataArr = [
        {
          label: '销售产品',
          arr: arrProdulist
        },
        {
          label: '业务销售',
          arr: arrBusiness
        }, {
          label: '财务管理',
          arr: arrFinance
        }
      ]
    },
    onEdit (row) {
      this.rowInfo = row
      this.updateVisible = true
    },
    afterSave () {
      this.loadList()
    },
    async onSwitch (row) {
      let status = row.status === '1' ? '0' : '1'
      await approveProcessApis.updateStatus({ id: row.id, status: status })
      this.$message.success('操作成功!')
      this.loadList()
    }
  }
}
</script>
